import { Module } from '@nestjs/common'
import { AuthController } from './auth.controller'
import { AuthService } from './auth.service'
import { TypeOrmModule } from '@nestjs/typeorm'
import { User } from '../user/entities/user.entity'
// 鉴权
import { PassportModule } from '@nestjs/passport'
import { LocalStorage } from './local.strategy'
import { JwtModule } from '@nestjs/jwt'
import { JwtStorage } from './jwt.strategy'
import { UserModule } from 'src/user/user.module'

const jwtModule = JwtModule.register({
  secret: 'test123456',
  signOptions: {
    expiresIn: '4h'
  }
})

// 异步从.env 环境变量中获取
// const jwtModule = JwtModule.registerAsync({
//   inject: [configService]
// })

@Module({
  imports: [
    TypeOrmModule.forFeature([User]),
    PassportModule,
    jwtModule,
    UserModule
  ],
  controllers: [AuthController],
  providers: [AuthService, LocalStorage, JwtStorage],
  exports: [jwtModule]
})
export class AuthModule {}
